<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <script type="text/javascript">
      /*
          json介绍
            1.定义格式 1：{key:value,key:value,...}
            2.定义格式 2：
                [{key:value,key:value,...},{key:value,key:value,...}，{key:value,key:value,...},...]
            3.定义格式 3：
                {key:value,key:[key:value,key1:value1,...],key:value,...}
       */
        //1.定义格式 1：{key:value,key:value,...}
        //TODO:person属于json对象名，如果想获取大括号中的value，需要使用: 对象名.name
        //person.address
        let person={"username":"柳岩","age":18,"address":"湖南"};
        //获取person中的湖南并输出控制台
        console.log(person.address);//湖南

        /*
             2.定义格式 2：
                [{key:value,key:value,...},{key:value,key:value,...}，{key:value,key:value,...},...]
        */
       let arr=[{"username":"柳岩","age":18,"address":"湖南"},{"username":"杨幂","age":20,"address":"北京"}];
       //获取20并输出控制台
       //arr[1] 获取的是{"username":"杨幂","age":20,"address":"北京"}，1表示索引
       console.log(arr[1].age);

       /*
         3.定义格式 3：
                {key:value,key:[key:value,key1:value1,...],key:value,...}
       */
      let person2={"username":"锁哥",students:[{"name":"孙磊","age":25},{"name":"陈浪","age":24}],"number":"itcast001"};
      //需求：获取陈浪并输出控制台
      // person2.students 获取的是[{"name":"孙磊","age":25},{"name":"陈浪","age":24}]
      //person2.students[1] 获取的是{"name":"陈浪","age":24}
      console.log(person2.students[1].name);//陈浪

  </script>
</body>
</html>